<template>
  <el-card>
    <div class="header">
      <i :class="{ 'el-icon-s-fold': !isCollapse, 'el-icon-s-unfold': isCollapse, }"
         @click="$emit('toggle-collapse')"
         class=" toggle "
      ></i>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item
          v-for="(item, index) in $route.matched"
          :key="index"
          style="font-size: 20px"
        >
          {{ item.name }}
        </el-breadcrumb-item>
      </el-breadcrumb>
      <div class="r-content">
        <el-dropdown>
                <span class="el-dropdown-link">
                    <img class="userCard" src="../../assets/tx.jpg" alt="">
                   <span class="username">admin</span>
                  <div class="change-icon">
   <i class="el-icon-setting"></i>
</div>
                </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>个人信息</el-dropdown-item>
            <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </el-card>
</template>

<script>
export default {
  props: ['isCollapse'],
  methods: {
    logout() {
      this.$confirm('您确定要退出登录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        console.log(111)
        window.sessionStorage.clear()
        this.$router.push('/login')
        history.pushState(null, null, document.URL)
        window.addEventListener('popstate', function (e) {
          history.pushState(null, null, document.URL)
        }, false)
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
}
</script>

<style scoped>
.el-breadcrumb ::v-deep .el-breadcrumb__inner {
  color: #4f5c97 !important;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between; /* 保持两端对齐 */
}

/* 将.r-content放置在右侧 */
.r-content {
  margin-left: auto; /* 自动外边距将.r-content推到最右侧 */
  display: flex;
  align-items: center; /* 确保所有子元素垂直居中 */
}

.el-dropdown-link {
  display: flex; /* 设置为flex容器 */
  align-items: center; /* 确保图片和文本垂直居中 */
}

.toggle {
  font-size: 28px;
}

.userCard {
  height: 40px;
  display: flex;
  border-bottom: 2px solid #dcdfe6;
  border-radius: 20px;
}

.username {
  padding: 10px;
  font-size: 24px;
  color: #333;
}

.change-icon {
  padding: 10px;
  font-size: 28px;
}
</style>
